import user from "../../../class/Utils/User"
import http from "../../../class/Utils/Http"
import tips from "../../../class/Utils/Tips"

Page({

  /**
   * 页面的初始数据
   */
  data: {
    menuid: '0',
    bangdingtoocletag: false,
  },
  
  onShow:function(){
    var that = this
    var user = wx.getStorageSync('user');
    console.log(user)

    if (!user) {
     console.log('没有登录')
    } else {
      that.setData({
        shouquan: 0,
        userinfo: user,
        user: user
      })
      
      /*
       判断有误 绑定
       */
      if (user.log == '1') {
        http.req('/Api/shengyihao', { uid: user.userid }, function (res) {
          console.log(res)
          that.setData({
            shengyihao: res
          })
        })
      }
    }
  },
  //打开导航
  menubtn: function (e) {
    var that = this
    var datamenuid = that.data.menuid
    var presentid = e.currentTarget.dataset.id
    if (presentid !== datamenuid){
      that.setData({
        menuid: presentid
      })
    }else{
      that.setData({
        menuid: 0
      })
    }
  },
  /*
     弹出 登录
     */
  bangdingtoocle: function () {
    var that = this
    that.setData({
      bangdingtoocletag: !that.data.bangdingtoocletag
    })
  },
  /*
   点击登录
   */
  denglu: function (e) {
    var that = this
    var zhanghao = e.detail.value.zhanghao
    var mima = e.detail.value.mima
    if (!zhanghao) {
      tips.error("账号不能为空");
      return false
    }
    if (!mima) {
      tips.error("密码不能为空");
    }
    http.req("/Api/log", { login: zhanghao, passwd: mima, uid: wx.getStorageSync('user').userid }, function (res) {
      console.log(res)
      if (res.code == '200') {
        var user = wx.getStorageSync('user')
        user.log = 1
        wx.setStorageSync('user', user)
        tips.ok('登录成功')
        that.setData({
          userinfo: user,
          bangdingtoocletag: false,
          shengyihao: zhanghao
        })
      } else {
        tips.error(res.msg_val)
      }
    })
  },
  //去会员中心
  gotomaincenter:function(){
    tips.godaohang('/pages/main/menu/menu');
  },
  

})